import { Component, OnInit } from '@angular/core';
import { ApiService } from '@core/services/http/api.service';
import { GridConfigService } from 'app/core/config/grid-config.service';
import { GridOptions } from '@ag-grid-community/core';
import { Router } from '@angular/router';
import { ApesMessageService } from '@shared/apes/message';
import { RenderOperatingButtonComponent } from '@shared/ag-grid-ext/cell-renders/render-operating-button.component';
import { dateFormat, exists } from '../../../utils/utils';
import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { ApesModalService } from '@shared/apes/modal';
import { DataKanbanDialogComponent } from './data-kanban-dialog.component';
import { ReuseTabService } from '@shared/apes/reuse-tab';
import { Events } from '@core/services/events/Events';
import { toNumber } from '@shared/apes/core/util/convert';
import { Subject } from 'rxjs/index';
import {AllModules, Module} from "@ag-grid-enterprise/all-modules";
import { PurchaseService } from '../../bi/purchase-report-form/purchase.service';

@Component({
  selector: 'data-kanban',
  templateUrl: './data-kanban.component.html',
  styleUrls: ['./data-kanban.component.scss'],
})
export class DataKanbanComponent implements OnInit {
  public modules: Module[] = AllModules;
  /* 按钮相关 */
  buttonBar = [
    { hide: true, style: 'primary', label: '查询', id: 'action_query', loading: false },
  ];

  isLoading$ = new Subject(); // 按键加载中
  loadingStep = 0; // 加载中步骤

  timeValue = 'today';
  timeList: any = [
    { name: '今天', value: 'today' },
    { name: '昨天', value: 'yesterday' },
    { name: '本周', value: 'week' },
    { name: '本月', value: 'month' },
  ];

  chauffeur: any = [];

  nowGird: any = 'findByUnassigned'; // 当前gird
  girdList: any = [
    {
      id: 'findByUnassigned',
      name: '未指派任务',
      num: 0,
      columnDefs: [
        {
          headerName: '',
          field: 'check',
          width: 40,
          pinned: 'left',
          headerCheckboxSelectionFilteredOnly: true,
          checkboxSelection: true,
        },
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          // headerCheckboxSelectionFilteredOnly: true,
          // checkboxSelection: true,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '线路名称', field: 'branchLineId', width: 200, valueFormatter: 'value.name' },
        { headerName: '运单总数', field: 'totalWaybill', width: 100 },
        {
          headerName: '操作', field: 'dialogButton', width: 100,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '查看详情',
              'hide': false,
              'disabled': false,
              'action': 'link',
              'routerData': true,
              'api': 'tms/dataKanban/dataKanbanParticularsComponent',
              'config': {
                'OAInterface': false,
                'api': 'tms.waybill.findByUnassignedDetail',
                'id': 'findByUnassigned',
              },
            },
          ],
          // callback: this.collectMaterials,
        },
      ],
      data: [],
    },
    {
      id: 'findByAssigned',
      name: '已指派任务',
      num: 0,
      columnDefs: [
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '线路名称', field: 'carInformation', width: 200, valueFormatter: 'value.branchLineId' },
        { headerName: '派车单', field: 'carInformation', width: 100, valueFormatter: 'value.id' },
        { headerName: '运单总数', field: 'totalWaybill', width: 100 },
        { headerName: '指派司机', field: 'carInformation', width: 100, valueFormatter: 'value.chauffeurId.name' },
        { headerName: '指派车辆', field: 'carInformation', width: 100, valueFormatter: 'value.vehicleId.vehicleNumber' },
        {
          headerName: '操作', field: 'dialogButton', width: 100,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '查看详情',
              'hide': false,
              'disabled': false,
              'action': 'link',
              'routerData': true,
              'api': 'tms/dataKanban/dataKanbanParticularsComponent',
              'config': {
                'OAInterface': false,
                'api': 'tms.waybill.findByAssignedDetail',
                'id': 'findByAssigned',
              },
            }],
        },
      ],
      data: [],
    },
    {
      id: 'findWaybillByStatus',
      name: '已装货',
      num: 0,
      columnDefs: [
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '派车单', field: 'carInformationId', width: 100, valueFormatter: 'value.id' },
        { headerName: '运单', field: 'waybillId', width: 100 },
        { headerName: '线路名称', field: 'branchLineId', width: 200 },
        { headerName: '发货地', field: 'deliveryAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '收货地', field: 'shippingAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '装货时间', field: 'loadingTime', width: 200, cellRenderer: this.transferTime },
        { headerName: '预计送达时间', field: 'arrivalTime', width: 200, cellRenderer: this.transferTime },
        { headerName: '物流司机', field: 'chauffeurId', width: 100, valueFormatter: 'value.name' },
        { headerName: '车辆', field: 'vehicleId', width: 100, valueFormatter: 'value.vehicleNumber' },
        {
          headerName: '货物信息', field: 'dialogButton', width: 100,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '货物详情',
              'title': '货物详情信息',
              'hide': false,
              'disabled': false,
              'action': 'drawer',
              'width': '45vw',
              'formId': 'tms.waybill.findByWaybill',
              'api': 'tms.waybill.findByWaybill',
            },
          ],
        },
      ],
      data: [],
    },
    {
      id: 'findWaybillByReceived',
      name: '已签收',
      num: 0,
      columnDefs: [
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '派车单', field: 'carInformationId', width: 100, valueFormatter: 'value.id' },
        { headerName: '运单', field: 'waybillId', width: 100 },
        { headerName: '线路名称', field: 'branchLineId', width: 200 },
        { headerName: '发货地', field: 'deliveryAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '收货地', field: 'shippingAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '装货时间', field: 'loadingTime', width: 200, cellRenderer: this.transferTime },
        { headerName: '签收时间', field: 'arrivalTime', width: 200, cellRenderer: this.transferTime },
        { headerName: '耗时(H)', field: 'consumeTime', width: 100 },
        { headerName: '物流司机', field: 'chauffeurId', width: 100, valueFormatter: 'value.name' },
        { headerName: '车辆', field: 'vehicleId', width: 100, valueFormatter: 'value.vehicleNumber' },
        {
          headerName: '货物信息', field: 'dialogButton', width: 100,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '货物详情',
              'title': '货物详情信息',
              'hide': false,
              'disabled': false,
              'action': 'drawer',
              'width': '45vw',
              'formId': 'tms.waybill.findByWaybill',
              'api': 'tms.waybill.findByWaybill',
            },
          ],
        },
      ],
      data: [],
    },
    {
      id: 'findWaybillByTransit',
      name: '中转暂存',
      num: 0,
      columnDefs: [
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '运单号', field: 'waybillId', width: 100 },
        { headerName: '来源单据', field: 'sourceBusinessKey', width: 100 },
        { headerName: '发货物流仓编码', field: 'deliveryAddress', width: 200, valueFormatter: 'value.id' },
        { headerName: '发货物理仓名称', field: 'deliveryAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '收货物流仓编码', field: 'shippingAddress', width: 200, valueFormatter: 'value.id' },
        { headerName: '收货物理仓名称', field: 'shippingAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '录入时间', field: 'transitDate', width: 200, cellRenderer: this.transferTime },
        {
          headerName: '货物信息', field: 'dialogButton', width: 100,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '货物详情',
              'title': '货物详情信息',
              'hide': false,
              'disabled': false,
              'action': 'drawer',
              'width': '45vw',
              'formId': 'tms.waybill.findByWaybill',
              'api': 'tms.waybill.findByWaybill',
            },
          ],
        },
      ],
      data: [],
    },
    {
      id: 'findByCollection',
      name: '采购揽件',
      num: 0,
      columnDefs: [
        {
          headerName: '序号',
          editable: false,
          field: 'sort',
          pinned: 'left',
          suppressMenu: true,
          width: 50,
          cellRenderer: this.sortCellRenderer,
          cellStyle: { textAlign: 'center' },
        },
        { headerName: '运单号', field: 'waybillId', width: 100 },
        { headerName: '采购订单号', field: 'purchaseOrder', width: 100 },
        { headerName: '供应商订单号', field: 'aimsKey', width: 100 },
        { headerName: '供应商名称', field: 'supplier', width: 100, valueFormatter: 'value.name' },
        { headerName: '联系方式', field: 'supplierPhone', width: 100 },
        { headerName: '要货仓库名称', field: 'shippingAddress', width: 200, valueFormatter: 'value.name' },
        { headerName: '交货方式名称', field: 'carryType', width: 100, valueFormatter: 'value.name' },
        { headerName: '生成时间', field: 'createDate', width: 100, cellRenderer: this.transferTime },
        {
          headerName: '操作', field: 'dialogButton', width: 200,
          widget: 'dialogButton',
          cellRenderer: 'dialogButton',
          buttonList: [
            {
              'id': 'search',
              'name': '货物详情',
              'title': '货物详情信息',
              'hide': false,
              'disabled': false,
              'action': 'drawer',
              'width': '45vw',
              'formId': 'tms.waybill.findByWaybill',
              'api': 'tms.waybill.findByWaybill',
            },
            // {
            //   'id': 'checked',
            //   'name': '确认揽件',
            //   'hide': false,
            //   'disabled': false,
            //   'action': 'confirm',
            //   'title': '确认已揽件！',
            //   'content': '确认已从供应商处取得货物！确认揽件后，要去未指派任务中指派司机、车辆，发往门店',
            // },
            {
              'id': 'checked',
              'name': '确认揽件',
              'hide': false,
              'disabled': false,
              'action': 'dialog',
              'compile':'true',
              'api': 'tms.waybill.confirmByWaybill'
            },
          ],
          callback: this.collectMaterials,
        },
      ],
      data: [],
    },
  ];
  itemsData: any = [];
  site: any = {};  // 物流站点
  supplierId: any = null; // 供应商
  aimsKey: any = null; // 供应商订单号
  offerGroupID: any
  offerGroup: any; // 报价组

  ctx = { model: {} };
  formId = 'tms/dataKanban/dataKanbanComponent';

  /** Grid 相关 **/
  rowData: any[] = [];
  gridApi: any;
  gridOptions: GridOptions;
  columnDefs: any[] = [];
  frameworkComponents;  // 框架组件
  height: any = window.innerHeight - 325 + 'px';

  // /** 时间相关 **/
  timeFrame: any = [];
  startValue: any = null;
  endValue: any = null;


  // formly 配置
  form = new FormGroup({});
  model: any = {};
  options: FormlyFormOptions = {};
  field: FormlyFieldConfig[] = [
    {
      key: 'chauffeur',
      type: 'select',
      templateOptions: {
        searchFormId: 'tms.chauffeur.findAll',
        downFormatter: '\'[ \' + value.id + \' ]\' + \' \' + value.name',
        valueFormatter: '\'[ \' + value.id + \' ]\' + \' \' + value.name',
        label: '批量指派司机',
        api: 'tms.chauffeur.findAllByKanBan',
        domain: '{"filters":[{"field":"name","operator":"like","value":"{{value}}"}],"groups":[],"operator":"and"}',
      },
    },
    {
      key: 'vehicle',
      type: 'select',
      templateOptions: {
        searchFormId: 'tms.vehicle.findAll',
        downFormatter: 'value.vehicleNumber + \' \' +  \'[ \' + value.vehicleStatus.description + \' ]\'',
        valueFormatter: 'value.vehicleNumber + \' \' +  \'[ \' + value.vehicleStatus.description + \' ]\'',
        label: '批量指派车辆',
        api: 'tms.vehicle.findAllByKanBan',
        domain: '{"filters":[{"field":"vehicleNumber","operator":"like","value":"{{value}}"}],"groups":[],"operator":"and"}',
      },
    },
  ];

  constructor(
    private apiService: ApiService,
    private msg: ApesMessageService,
    private event: Events,
    private modalService: ApesModalService,
    protected rs: ReuseTabService,
    private router: Router,
    private gridConfigService: GridConfigService,
    private pa: PurchaseService,
  ) {

    // 初始化 grid
    this.gridOptions = <GridOptions>{
      toolPanelSuppressSideButtons: true,
      suppressExcelExport: true,
      suppressCsvExport: true,
      suppressSizeToFit: true,
      showToolPanel: false,
      pagination: true,
      paginationPageSize: 50,
      rowHeight: 35,
    };
    this.gridOptions.localeText = this.gridConfigService.getLocaleText();
  }

  ngOnInit() {

    this.isLoading$.subscribe((data:number)=>{
      this.loadingStep += data;
      // console.log('step' + this.loadingStep);
      if(this.loadingStep>0){
        this.buttonBar[0].loading = true;
      }else{
        this.buttonBar[0].loading = false;
      }
    });

    this.columnDefs = [];
    this.columnDefs = this.girdList[0].columnDefs;
    this.rowData = this.girdList[0].data;
    this.frameworkComponents = {
      dialogButton: RenderOperatingButtonComponent,
    };

    this.pa.getOfferGroup().then(value => { this.offerGroup = value });

    this.initLogistics();

    // 确认揽件
    this.event.subscribe(this.formId, (data) => {
      let api = 'tms.waybill.collection';
      // console.log(data);
      this.apiService.post(api, { 'body': JSON.stringify(data) }).subscribe((body) => {

        if (body) {
          this.msg.success('揽件成功');
          this.openPrint(data);
        }
        this.queryData();
      });
    });
  }

  onGridReady(params) {
    this.gridApi = params.api;
  }

  sortCellRenderer(params) {
    return params.rowIndex + 1;
  }

  transferTime(params) {

    return dateFormat('yyyy-MM-dd HH:mm:ss', new Date(params.value));
  }

  btnChange(list: any) {
    this.nowGird = list.id;
    if (this.nowGird == 'findByUnassigned') {
      if (list.data.length != 0) {
        list.data.forEach((row) => {
          row.selected = false;
        });
      }
    }
    this.columnDefs = list.columnDefs;
    this.rowData = list.data;
  }

  /**
   * 功能：按钮事件路由
   * @param data 当前按钮元数据
   */
  onEvent(data: any) {

    if (data instanceof MouseEvent) return;
    if (data) {
      if (data.id === 'action_query') {
        this.buttonBar[0].loading = true;
        this.queryData();
      }
    }
  }

  // 初始化物流站点
  initLogistics() {

    // tms.site.findAllOperate
    let api = 'tms.site.findAllOperateNoPage';

    const data = {};

    this.apiService.post(api, { 'body': JSON.stringify(data) }).subscribe((body) => {

      if (body.length != 0) {
        this.itemsData = body;
        this.site = body[0];
      }

      this.queryData();
    });
  }

  // 查询数据
  queryData() {

    if (this.timeFrame.length !== 0) {
      this.getDate(this.timeFrame, 'startValue', 'endValue');
    } else {
      this.checkTimeValue();
    }

    // if(this.site == null){
    //   this.msg.error('请选择物流站点');
    //   this.buttonBar[0].loading = false;
    //   return;
    // }

    const data = {
      startValue: this.startValue,
      endValue: this.endValue,
      site: this.site,
      aimsKey: toNumber(this.aimsKey),
      supplier_id: this.supplierId,
      bjz: this.offerGroupID
    };

    // let api = 'tms.waybill.getLocationService';       // 查询全部
    // let api = 'tms.waybill.findByUnassigned';      // 查询未指派任务
    // let api = 'tms.waybill.findByAssigned';        // 查询已指派任务
    // let api = 'tms.waybill.findWaybillByStatus';   // 查询已装货
    // let api = 'tms.waybill.findWaybillByReceived'; // 查询已签收
    // let api = 'tms.waybill.findWaybillByTransit';  // 查询中转暂存
    // let api = 'tms.waybill.findByCollection';      // 查询采购揽件

    let arr = [
      'tms.waybill.findByUnassigned',
      'tms.waybill.findByAssigned',
      'tms.waybill.findWaybillByStatus',
      'tms.waybill.findWaybillByReceived',
      'tms.waybill.findWaybillByTransit',
      'tms.waybill.findByCollection',
    ];

    this.girdList.forEach((gird) => {
      gird.num = 0;
      gird.data = [];
    });
    this.rowData = [];

    arr.forEach((api)=>{
      this.getPostData(api,data);
    })

    // this.buttonBar[0].loading = true;

    // this.isLoading$.next(1);
    // this.apiService.post(api, { 'body': JSON.stringify(data) }).subscribe((body) => {
    //
    //   if (body) {
    //     body.forEach((list) => {
    //       this.girdList.forEach((gird) => {
    //         if (gird.id == list.id) {
    //           gird.num = list.num;
    //           gird.data = list.data;
    //         }
    //       });
    //       if (this.nowGird == list.id) {
    //         this.rowData = list.data;
    //       }
    //     });
    //   }
    //   this.isLoading$.next(-1);
    //
    // });

  }

  getPostData(api,data){
    this.isLoading$.next(1);
    this.apiService.post(api, { 'body': JSON.stringify(data) }).subscribe((body) => {
      if (body) {
        body.forEach((list) => {
          this.girdList.forEach((gird) => {
            if (gird.id == list.id) {
              gird.num = list.num;
              gird.data = list.data;
            }
          });
          if (this.nowGird == list.id) {
            this.rowData = list.data;
          }
        });
      }
      this.isLoading$.next(-1);
    });
  }

  // 确认指派
  clickDesignate() {
    let selectData = [];
    this.rowData.forEach((row) => {
      if (row.selected) {
        selectData.push(row);
      }
    });

    if (this.model['chauffeur'] == null) {
      this.msg.error('请选择指派司机');
      return;
    } else if (this.model['vehicle'] == null) {
      this.msg.error('请选择指派车辆');
      return;
    } else if (selectData.length == 0) {
      this.msg.error('请选择指派线路');
      return;
    }

    const data = {
      ...this.model,
      assignedList: selectData,
    };

    let api = 'tms.waybill.assigned';

    this.apiService.post(api, { 'body': JSON.stringify(data) }).subscribe((body) => {

      if (body) {
        this.msg.success('指派成功');
        this.queryData();
      }
    });
  }

  // 中转收件
  clickTransfer() {
    let params = {};
    let dialog;
    const openDialog = dialog ? dialog : DataKanbanDialogComponent;
    const dialogRef = this.modalService.create({
      apesWidth: 800,
      apesMaskClosable: false,
      apesTitle: '中转收件',
      // apesWrapClassName: 'modal-lg',
      apesContent: openDialog,
      apesComponentParams: params,
      apesFooter: [
        {
          label: '取消',
          type: 'default',
          onClick: () => {
            dialogRef.close();
          },
        },
        {
          label: '确定',
          type: 'primary',
          disabled: (componentInstance) => {
            let disabled = false;
            if (componentInstance['carInformationId'] == '') {
              disabled = true;
            } else if (componentInstance['site'] == '') {
              disabled = true;
            }
            return disabled;
          },
          onClick: (componentInstance) => {
            let api = 'tms/dataKanban/dataKanbanTransferComponent';
            let carInformationId = componentInstance['carInformationId'];
            let site = componentInstance['site'];
            dialogRef.destroy();
            let data = {
              carInformationId: carInformationId,
              site: site,
            };
            this.switchLink(data, api);
          },
        },
      ],
    });
  }

  // 用于获取单选框日期时间
  checkTimeValue() {
    let data = this.timeValue;
    let nowDate = new Date(new Date().toLocaleDateString());
    let startDates: any;
    let endDates: any;
    if (data == 'today') {
      startDates = nowDate;
      endDates = new Date(nowDate.getTime() + (24 * 60 * 60 * 1000 - 1));
    } else if (data == 'yesterday') {
      startDates = new Date(nowDate.getTime() - (3600 * 1000 * 24));
      endDates = new Date(nowDate.getTime() - 1000);
    }
    else if (data == 'week') {
      let Monday = this.getWeekFirstDayDateZeroTime(nowDate);
      startDates = Monday;
      endDates = new Date(Monday.getTime() + (3600 * 1000 * 24 * 7 - 1000));
    }
    else if (data == 'month') {
      startDates = this.getThisMonthFirstDayDateZeroTime(nowDate);
      endDates = this.getThisMonthLastDayDateTime(nowDate);
    }
    this.startValue = dateFormat('yyyy-MM-dd HH:mm:ss', startDates);
    this.endValue = dateFormat('yyyy-MM-dd HH:mm:ss', endDates);
  }

  // 用于获取本周第一天
  getWeekFirstDayDateZeroTime(date) {
    let nowTemp = new Date(date);         // 当前时间
    let oneDayLong = 24 * 60 * 60 * 1000; // 一天的毫秒数
    let c_time = nowTemp.getTime();       // 当前时间的毫秒时间
    let c_day = nowTemp.getDay() || 7;    // 当前时间的星期几
    let m_time = c_time - (c_day - 1) * oneDayLong; // 当前周一的毫秒时间
    return new Date(m_time);             // 当前周一0点时间戳
  }

  // 用于获取本月第一天
  getThisMonthFirstDayDateZeroTime(date) {
    date.setDate(1);
    return date;
  }

  // 用于获取本月最后一天
  getThisMonthLastDayDateTime(date) {
    let data = new Date();
    // if (data.getMonth() == 11) {
    //   data.setMonth(0);
    // } else {
    data.setMonth(date.getMonth() + 1);
    // }
    data.setDate(1);
    data.setHours(0);
    data.setSeconds(0);
    data.setMinutes(0);
    data = new Date(data.getTime() - 1000);
    return data;
  }

  // 用于灌起始结束时间
  getDate(time: any[], time_ks: string, time_js: string) {
    const [first, second] = time;
    if (first) {
      // this[time_ks] = first.toISOString().slice(0, 10);
      let _ks = first.toLocaleDateString();
      this[time_ks] = dateFormat('yyyy-MM-dd HH:mm:ss', new Date(_ks));
    } else {
      this[time_ks] = null;
    }

    if (second) {
      // this[time_js] = second.toISOString().slice(0, 10);
      let _js = new Date(second.toLocaleDateString()).getTime() + (24 * 60 * 60 * 1000 - 1);
      this[time_js] = dateFormat('yyyy-MM-dd HH:mm:ss', new Date(_js));
    } else {
      this[time_js] = null;
    }
  }

  // grid选中
  onSelectionChanged($event) {
    this.gridApi.forEachNode((node) => {
      let selected = node.isSelected();
      // 用于处理隐藏checkbox
      // if (node.data['hideSelected'] == true) {
      //   node.data['selected'] = false;
      // } else {
      node.data['selected'] = selected;
      // }
    });
  }

  // 中转路由跳转
  switchLink(data: any, method: string) {
    if (method == null) {
      this.msg.error('该链接尚未存在，麻烦核实！', { 'apesDuration': 5000 });
      return false;
    }
    const formId = method;
    const url = '/' + formId;
    this.gridConfigService.setRouterData(data, formId);
    if (this.rs.exists(url) || this.rs.curUrl === url) {
      this.router.navigateByUrl(formId);
    } else {
      this.router.navigate([formId]);
    }
  }

  // 确定揽件
  collectMaterials(params) {

    let data = params.data['data'];
    let formId = 'tms/dataKanban/dataKanbanComponent';
    params.event.publish(formId, data);

  }

  // 采购揽件打印
  openPrint(params) {
    let reportUrl;
    this.apiService.post('report.getUrl', {}).subscribe((body) => {
      if (exists(body)) {
        reportUrl = body;
        let reportName = 'tms_waybill.ureport.xml';
        let id = params['waybillId'];
        window.open(reportUrl + reportName + '&id=' + id);
      }
    });
  }

}
